package com.app.couponsharelife.ui.main.home.local

import android.content.Intent
import android.os.Bundle
import androidx.recyclerview.widget.GridLayoutManager
import com.app.couponsharelife.R
import com.app.couponsharelife.base.LazyFragment
import com.app.couponsharelife.data.bean.LifeHomePageBean
import com.app.couponsharelife.ui.adapter.LocalShopsTypeAdapter
import com.app.couponsharelife.ui.listener.OnClickListener
import kotlinx.android.synthetic.main.fragment_local_shops_type.*

class LocalShopsTypeFragment : LazyFragment() {

    override val viewLayoutId: Int get() = R.layout.fragment_local_shops_type

    private var classifyListBean: LifeHomePageBean.ClassifyListBean? = null

    companion object {
        fun newInstance(classify: LifeHomePageBean.ClassifyListBean): LocalShopsTypeFragment {
            val fragment = LocalShopsTypeFragment()
            val bundle = Bundle()
            bundle.putSerializable("list", classify)
            fragment.arguments = bundle
            return fragment
        }
    }

    override fun initViews() {
        classifyListBean = arguments!!.getSerializable("list") as LifeHomePageBean.ClassifyListBean
        initRecyclerView()
    }

    private fun initRecyclerView() {
        mRecyclerView.layoutManager = GridLayoutManager(context, 5)
        mRecyclerView.adapter = LocalShopsTypeAdapter(classifyListBean?.classify!!, object : OnClickListener {
            override fun click(arg1: Int, arg2: Any) {
                val intent = Intent(context, LocalShopsListActivity::class.java)
                intent.putExtra("classId", (arg2 as LifeHomePageBean.ClassifyBean).id)
                startActivity(intent)
            }
        })
    }

    override fun lazyLoad() {

    }
}